package com.ctgu.computer.service.impl;

import com.ctgu.computer.common.UserLocalTread;
import com.ctgu.computer.domain.dto.PageQueryDTO;
import com.ctgu.computer.domain.po.AdminInfo;
import com.ctgu.computer.domain.po.UserInfo;
import com.ctgu.computer.domain.result.PageResult;
import com.ctgu.computer.mapper.AdminMapper;
import com.ctgu.computer.mapper.UserMapper;
import com.ctgu.computer.service.AdminService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.dromara.x.file.storage.core.FileStorageService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AdminServiceImpl implements AdminService {
    private final AdminMapper adminMapper;
    private final FileStorageService fileStorageService;

    @Override
    public AdminInfo getInfo() {
        Integer adminId = UserLocalTread.getAdminId();
        return adminMapper.selectAdminInfoById(adminId);
    }

    @Override
    public AdminInfo getById(Integer adminId) {
        return adminMapper.selectAdminInfoById(adminId);
    }

    @Override
    public void updateAdminInfo(AdminInfo adminInfo) {
        adminMapper.updateAdminInfo(adminInfo);
    }

    @Override
    public PageResult page(PageQueryDTO pageQueryDTO) {
        PageHelper.startPage(pageQueryDTO.getPageIndex(), pageQueryDTO.getPageSize());
        Page<AdminInfo> adminInfos = adminMapper.list(pageQueryDTO);
        return new PageResult(adminInfos.getTotal(),adminInfos.getResult());
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        adminMapper.deleteByIds(ids);
    }
}
